# 爬取的目标url
import requests
from lxml import etree

url = 'https://movie.douban.com/top250'

# 请求头设置
headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36'
}

# 发送请求
res = requests.get(url, headers=headers)

# 用 lxml 将结果解析为 html
html = etree.HTML(res.text)

name = html.xpath("//div[@class='hd']/a/span[1]/text()")
score = html.xpath('//*[@id="content"]/div/div[1]/ol/li[*]/div/div[2]/div[2]/div/span[2]/text()')

# 拉链函数, 将两个列表,组装成元组
re = list(zip(name, score))
print(re)
